/**
 * vuex 响应式状态管理
 */

import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    IP: "http://47.103.128.167:9191",
    language: false, // 1 中文  2 英文  .....
    typeCategoryId: false,
    langCategoryId: false,
    audio: [],
    audioIndex: false
  },
  mutations: {
    setIP(state, n) {
      state.IP = n;
    },
    setLanguage(state, n) {
      state.language = n;
    },
    setTypeCategoryId(state, n) {
      state.typeCategoryId = n;
    },
    setLangCategoryId(state, n) {
      state.langCategoryId = n;
    },
    setNowSong(state, n) {
      state.nowSong = n;
    },
    setNowSongIndex(state, n) {
      state.nowSong.index = n;
    },
    // 添加歌曲到播放列表   删除播放列表中的歌曲
    setAudio(state, n) {
      if (n[0] == "push") {
        state.audio.push(n[1]);
        state.audioIndex = state.audio.length - 1;
      } else if (n[0] == "delete") {
        let audio = state.audio;
        delete audio[n[1]];
        let newAudio;
        for (let index = 0; index < audio.length; index++) {
          newAudio[index] = audio[index];
        }
        if (state.audio.length < 2) {
          state.audioIndex = false;
        } else {
          state.audioIndex = state.audio.n[1] - 1;
        }
      } else if (n[0] == "deleteAll") {
        state.audio = [];
        state.audioIndex = false;
      }
    },
    setAudioIndex(state, n) {
      state.audioIndex = n;
    }
  },
  actions: {},
  getters: {
    getLanguage(state) {
      return state.language;
    },
    getTypeCategoryId(state) {
      return state.typeCategoryId;
    },
    getLangCategoryId(state) {
      return state.langCategoryId;
    },
    getNowSong(state) {
      return state.nowSong;
    },
    getAudio(state) {
      return state.audio;
    },
    getAudioIndex(state) {
      return state.audioIndex;
    },
    getIP(state) {
      return state.IP;
    }
  }
});
